package com.fyzk.activity.lottery.jc.beidan;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tyjc.lottery.R;

import java.util.List;

/**
 * Created by fanxs11 on 2017/11/22.
 */

public class BeiDan_SXDS_PayAdapter extends BeiDanBasePayAdapter {

    public BeiDan_SXDS_PayAdapter(Context context, List<BeiDanChildBean> infors, OnBeiDanPayClickListerner listerner) {
        super(context, infors, listerner);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final BeiDanChildBean info = infors.get(i);
        ViewHolder holder = null;
        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.adapter_beidan_sxds_pay, null);
            holder.zhu = view.findViewById(R.id.beidan_pay_list_item_zhu);
            holder.delete = view.findViewById(R.id.beidan_pay_list_item_delete);
            holder.home = view.findViewById(R.id.beidan_pay_list_item_home);
            holder.vs = view.findViewById(R.id.beidan_pay_list_item_vs);
            holder.away = view.findViewById(R.id.beidan_pay_list_item_away);
            holder.week_num = view.findViewById(R.id.beidan_pay_list_matchnum);
            holder.sxds_sd = view.findViewById(R.id.beidan_pay_list_item_sxds_sd);
            holder.sxds_ss = view.findViewById(R.id.beidan_pay_list_item_sxds_ss);
            holder.sxds_xd = view.findViewById(R.id.beidan_pay_list_item_sxds_xd);
            holder.sxds_xs = view.findViewById(R.id.beidan_pay_list_item_sxds_xs);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.week_num.setText(info.getMatchNum()+"");
        holder.home.setText(info.getHomeTeam());
        holder.away.setText(info.getAwayTeam());

        holder.sxds_sd.setText("上单\n"+info.getSxds_01());
        holder.sxds_ss.setText("上双\n"+info.getSxds_00());
        holder.sxds_xd.setText("下单\n"+info.getSxds_11());
        holder.sxds_xs.setText("下双\n"+info.getSxds_10());

        holder.sxds_sd.setChecked(info.isSxds_sd);
        holder.sxds_ss.setChecked(info.isSxds_ss);
        holder.sxds_xd.setChecked(info.isSxds_xd);
        holder.sxds_xs.setChecked(info.isSxds_xs);
        info.refreshSXDS();
        jiSuanZhuShu();

        holder.sxds_sd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isSxds_sd = !info.isSxds_sd;
                if (info.isSxds_sd) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.sxds_ss.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isSxds_ss = !info.isSxds_ss;
                if (info.isSxds_ss) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.sxds_xd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isSxds_xd = !info.isSxds_xd;
                if (info.isSxds_xd) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.sxds_xs.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isSxds_xs = !info.isSxds_xs;
                if (info.isSxds_xs) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.clearAll();
                infors.remove(info);
                notifyDataSetChanged();
                if (infors.size() == 0) {
                    jiSuanZhuShu();
                }
            }
        });

        return view;
    }

    @Override
    protected void jiSuanZhuShu() {

        if (listerner != null) {
            listerner.onItemClick();
        }
    }

    class ViewHolder {
        LinearLayout zhu;
        LinearLayout delete;
        TextView home;
        TextView week_num;
        TextView vs;
        TextView away;
        CheckBox sxds_sd;
        CheckBox sxds_ss;
        CheckBox sxds_xd;
        CheckBox sxds_xs;

    }
}
